#include <iostream>
#define lc p << 1
#define rc p << 1 | 1
// zdl:: 这道题目还是很简单的
using namespace std;
const int num = 1e5 + 10;

struct node
{
    int l, r, sum, cnt;

}tr[num << 2];

int n,m;
int a[num];
void pushUp(int p)
{
    tr[p].sum = tr[lc].sum + tr[rc].sum;
}

void bulid (int p, int l, int r)
{
    tr[p] = {l, r, 0, 0};
    if (l == r) return;
    int mid = (l + r) >> 1;
    bulid (lc, l, mid), bulid(rc, mid + 1, r);
    pushUp(p);
}
void lazy(int p, int cnt)
{
    if (cnt % 2 == 1) tr[p].sum = tr[p].r - tr[p].l + 1 - tr[p].sum; 
    tr[p].cnt += cnt;
}
void pushDown(int p)
{
    lazy(lc, tr[p].cnt);
    lazy(rc, tr[p].cnt);
    tr[p].cnt = 0;
}
void modify(int p, int a, int b)
{
    // 关的开， 开的关
    int l = tr[p].l, r = tr[p].r;
    if (a <= l && r <= b)
    {
        lazy(p, 1);
        return ;
    } 
    pushDown(p);

    int mid{(l + r) >> 1};
    if (a <= mid) modify(lc, a, b);
    if (b >= mid + 1) modify(rc, a, b);
    pushUp(p);
}
int query(int p, int a, int b)
{
    int l = tr[p].l, r = tr[p].r;
    if (a <= l && r <= b) return tr[p].sum;

    int mid((l + r) >> 1);
    pushDown(p);
    int sum = 0;
    if (a <= mid) sum += query(lc, a, b);
    if (b >= mid + 1) sum += query(rc, a, b);
    // pushUp(p);
    return sum;
}
int main()
{
    cin >> n >> m;
    // for (int i = 1; i <= n; i++) cin >> a[i];
    bulid(1, 1, n);
    int c, a, b;
    while (m--)
    {
        cin >> c >> a >> b;
        if (c== 0)
        {
            modify(1, a, b);
        }
        else cout << query(1, a, b) << endl;
    }
    return 0;
}


// turn the light 